import UtilsTemplate from '../../../components/UtilsTemplate';
import {storageSet,storageGet,storageDel} from '@/util/common';
export default {
	extends:UtilsTemplate,
	data(){
		return {
			apis:[
				{
					name:'存储数据',
					info:'向localStorage存储数据',
					code:`
<script>
import {storageSet} from '@lexmis/baseui/src/util/common';

//没有函数
storageSet('test1',{
	a:1,
	b:true,
	c:'测试',
	e:function(a,b){
		return a+b;
	}
});
//含有函数
storageSet('test2',{
	a:1,
	b:true,
	c:'测试',
	e:function(a,b){
		return a+b;
	}
},true);
</${'script'}>`,
					tabs:[
						{
							name:'storageSet(key, value, storeFn) => void',
							args:[
								{name:'key',info:'存储的键名',type:'string',def:''},
								{name:'value',info:'需要存储的数据',type:'any',def:''},
								{name:'storeFn',info:'是否存储函数',type:'boolean',def:'false'},
							]
						}
					]
				},{
					name:'获取数据',
					info:'向localStorage获取已经存储的数据',
					code:`
<script>
import {storageGet} from '@lexmis/baseui/src/util/common';

storageGet('test1'); //{a:1,b:true,c:"测试"}
storageGet('test2',true); //{a:1,b:true,c:"测试",e:function(a,b){return a+b;}}
</${'script'}>`,
					tabs:[
						{
							name:'storageGet(key, storeFn) => any',
							args:[
								{name:'key',info:'存储的键名',type:'string',def:''},
								{name:'storeFn',info:'是否存储函数',type:'boolean',def:'false'},
							]
						}
					]
				},{
					name:'删除数据',
					info:'向localStorage删除已经存储的数据',
					code:`
<script>
import {storageDel,storageGet} from '@lexmis/baseui/src/util/common';

storageDel('test1');
storageDel('test2');
storageGet('test1'); //null
storageGet('test2',true); //null
</${'script'}>`,
					tabs:[
						{
							name:'storageDel(key) => void',
							args:[
								{name:'key',info:'存储的键名',type:'string',def:''},
							]
						}
					]
				}
			],
		};
	},
};
(function(){
	console.log('=========存储数据=========');
	//没有函数
	storageSet('test1',{
		a:1,
		b:true,
		c:'测试',
		e:function(a,b){
			return a+b;
		}
	});
	//含有函数
	storageSet('test2',{
		a:1,
		b:true,
		c:'测试',
		e:function(a,b){
			return a+b;
		}
	},true);
})();
(function(){
	console.log('=========获取数据=========');
	console.log(storageGet('test1'));
	console.log(storageGet('test2',true));
})();
(function(){
	console.log('=========获取数据=========');
	storageDel('test1');
	storageDel('test2');
	console.log(storageGet('test1'));
	console.log(storageGet('test2',true));
})();
